package com.mt.constants;

import com.mt.enums.Status;

import java.io.Serializable;

/**
 * @author Wang
 * @Description JSON返回格式类
 * @date 2020/11/9-15:53
 */
public class Result<T> implements Serializable {
    private  String msg;
    private Integer code;
    private  T data;


    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public void  success(T data){
        this.setMsg(Status.SUCCESS.getMsg());
        this.setCode(Status.SUCCESS.getCode());
        this.setData(data);
    }
    public void  success(){
        this.setMsg(Status.SUCCESS.getMsg());
        this.setCode(Status.SUCCESS.getCode());
    }

    public void  error(T data){
        this.setMsg(Status.ERROR.getMsg());
        this.setCode(Status.ERROR.getCode());
        this.setData(data);
    }
    public void  error(Status status,T data){
        this.setMsg(status.getMsg());
        this.setCode(status.getCode());
        this.setData(data);
    }
}
